/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rekap;

import com.view.*;
import com.model.Member;
import com.model.Paket;
import com.model.Pesanan;
import com.tools.koneksi;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Satellite
 */
public class TableKontrolPesanan {

    private Connection conn;

    public TableKontrolPesanan(Connection koneksi) {
        this.conn = koneksi;
    }

    public static TableKontrolPesanan getKoneksiKategori() throws SQLException {
        koneksi k = new koneksi();
        TableKontrolPesanan kon = new TableKontrolPesanan(k.getDBConnection());
        return kon;
    }

    public List<Pesanan> lihatSeluruhKategori() throws SQLException {
        PreparedStatement statement = null;
        ResultSet result = null;

        conn.setAutoCommit(false);

        statement = conn.prepareStatement("select * from pesanan");

        result = statement.executeQuery();
        List<Pesanan> kategoris = new ArrayList<Pesanan>();
        while (result.next()) {
            Pesanan kategori = new Pesanan();
            kategori.setTelp(result.getString("notelp"));
            kategori.setId_pesanan(result.getString("idpesanan"));
            kategori.setNama(result.getString("nama"));
            kategori.setPaket(result.getString("paket"));
            kategori.setJadi(result.getString("tanggaljadi"));
//            String jml = result.getString("jumlah");
            kategori.setJumlah(result.getInt("jumlah"));
            kategori.setTotal(result.getDouble("hargatotal"));
            kategori.setAlamat(result.getString("alamat"));
            kategori.setId_member(result.getString("idmember"));
            kategori.setStatus(result.getString("status"));
            kategori.setPengiriman(result.getString("pengiriman"));
            kategoris.add(kategori);

        }
        conn.commit();
        return kategoris;
    }
        public void tambah(Paket menu) throws SQLException {
        PreparedStatement statement = null;
        try {
            conn.setAutoCommit(false);
            String sql = "insert into "
                    + " paket (nama_paket, harga_paket, nasi, lauk, sayur, kerupuk, minum)"
                    + " values(?,?,?,?,?,?,?)";
            statement = conn.prepareStatement(sql);
            statement.setString(1, menu.getNamaPaket());
            statement.setInt(2, menu.getHargaPaket());
            statement.setString(3, menu.getNasi());
            statement.setString(4, menu.getLauk());
            statement.setString(5, menu.getSayur());
            statement.setString(6, menu.getKrupuk());
            statement.setString(7, menu.getMinum());

            statement.executeUpdate();
            conn.commit();
        } catch (SQLException e) {
            conn.rollback();
            throw e;
        } finally {
            try {
                conn.setAutoCommit(true);
                if (statement != null) {
                    statement.close();
                }
            } catch (SQLException e) {
                throw e;
            }
        }
    }
}
